450B - Jzzhu and Sequences - CodeForces Solution


implementation math *1300

Please click on ads to support us..

Python Code:

x, y = map(int, input().split())
n = int(input())
lst = [x, y]
i = 1
while i < 6:
    p = lst[i] - lst[i-1]
    lst.append(p)
    i += 1
ans = lst[(n-1)%6]
print(ans%(10**9 + 7))

C++ Code:

#include <bits/stdc++.h>
using namespace std;

const int num=1e9+7;

int main()
{
    int x,y;
    cin>>x>>y;
    long long n;cin >>n;
    if(x<0)
        x+=num;
    if(y<0)
        y+=num;
    int z=(y%num-x%num +num)%num;
    int rem=n%6;
    if(rem==0)
        cout<<(-z+num)%num<<"\n";
    if(rem==1)
        cout<<x<<"\n";
    if(rem==2)
        cout<<y<<"\n";
    if(rem==3)
        cout<<z<<"\n";
    if(rem==4)
        cout<<(-x+num)%num<<"\n";
    if(rem==5)
        cout<<(-y+num)%num<<"\n";
}


Comments

Submit
0 Comments
More Questions

876A - Trip For Meal
1326B - Maximums
1635C - Differential Sorting
961A - Tetris
1635B - Avoid Local Maximums
20A - BerOS file system
1637A - Sorting Parts
509A - Maximum in Table
1647C - Madoka and Childish Pranks
689B - Mike and Shortcuts
379B - New Year Present
1498A - GCD Sum
1277C - As Simple as One and Two
1301A - Three Strings
460A - Vasya and Socks
1624C - Division by Two and Permutation
1288A - Deadline
1617A - Forbidden Subsequence
914A - Perfect Squares
873D - Merge Sort
1251A - Broken Keyboard
463B - Caisa and Pylons
584A - Olesya and Rodion
799A - Carrot Cakes
1569B - Chess Tournament
1047B - Cover Points
1381B - Unmerge
1256A - Payment Without Change
908B - New Year and Buggy Bot
979A - Pizza Pizza Pizza